package com.nuanshui.heatedloan.userinfo.service.thirdLogin;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserService;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserServiceFactory;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserServiceNameConverter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by zxh on 2017/2/10.
 */
@Service("ThirdUserServiceFactory")
@Transactional(readOnly=true,value= TransactionManagerType.USER_INFO_TRANSACTION_MANAGER)
public class ThirdUserServiceFactoryImpl implements ThirdUserServiceFactory,BeanFactoryAware {

    private ThirdUserServiceNameConverter converter=new ThirdUserServiceNameConverter();

    @Override
    public ThirdUserService GetThirdUserService(int accountType)
    {
         String serviceName=converter.convert(accountType);

         return GetThirdUserService(serviceName);
    }

    @Override
    public ThirdUserService GetThirdUserService(String name)
    {
        if(beanFactory.containsBean(name))
           return (ThirdUserService)beanFactory.getBean(name);

        return null;
    }

    private BeanFactory beanFactory;

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory=beanFactory;
    }
}
